import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { LawCaseContentApi } from '#/api/law/caseContent';
import type { DescriptionItemSchema } from '#/components/description';

import { h } from 'vue';

import { formatDate } from '@vben/utils';

import { Typography } from 'ant-design-vue';

const { Paragraph } = Typography;
/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'id',
      component: 'Input',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'contentHash',
      label: '内容SHA256哈希',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入内容SHA256哈希',
      },
    },
    {
      fieldName: 'caseNo',
      label: '案号',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入案号',
      },
    },
    {
      fieldName: 'caseCause',
      label: '案由',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入案由',
      },
    },
    {
      fieldName: 'trialProcedure',
      label: '审理程序（一审/二审/再审等）',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入审理程序（一审/二审/再审等）',
      },
    },
    {
      fieldName: 'courtName',
      label: '审理法院',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入审理法院',
      },
    },
    {
      fieldName: 'judgmentDate',
      label: '裁判时间',
      rules: 'required',
      component: 'DatePicker',
      componentProps: {
        showTime: false,
        format: 'YYYY-MM-DD',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'partyInfo',
      label: '当事人信息结构化数据(zlib压缩)',
      component: 'Textarea',
      formItemClass: 'col-span-2',
      componentProps: {
        placeholder: '请输入当事人信息结构化数据(zlib压缩)',
      },
    },
    {
      fieldName: 'judgmentResult',
      label: '裁判结果',
      component: 'Textarea',
      formItemClass: 'col-span-2',
      componentProps: {
        placeholder: '请输入裁判结果',
      },
    },
    {
      fieldName: 'disputeFocus',
      label: '争议焦点(zlib压缩)',
      component: 'Textarea',
      formItemClass: 'col-span-2',
      componentProps: {
        placeholder: '请输入争议焦点(zlib压缩)',
      },
    },
    {
      fieldName: 'caseSummary',
      label: '案件概述(zlib压缩)',
      component: 'Textarea',
      formItemClass: 'col-span-2',
      componentProps: {
        placeholder: '请输入案件概述(zlib压缩)',
      },
    },
    {
      fieldName: 'courtFindings',
      label: '法院查明(zlib压缩)',
      component: 'Textarea',
      formItemClass: 'col-span-2',
      componentProps: {
        placeholder: '请输入法院查明(zlib压缩)',
      },
    },
    {
      fieldName: 'courtOpinion',
      label: '法院认为(zlib压缩)',
      component: 'Textarea',
      formItemClass: 'col-span-2',
      componentProps: {
        placeholder: '请输入法院认为(zlib压缩)',
      },
    },
    {
      fieldName: 'fullText',
      label: '全文压缩',
      component: 'Textarea',
      formItemClass: 'col-span-2',
      componentProps: {
        placeholder: '请输入全文压缩',
      },
    },
    {
      fieldName: 'textLength',
      label: '原文长度',
      component: 'Input',
      componentProps: {
        placeholder: '请输入原文长度',
      },
    },
    {
      fieldName: 'judicialRules',
      label: '适用法条',
      component: 'Textarea',
      formItemClass: 'col-span-2',
      componentProps: {
        placeholder: '请输入适用法条',
      },
    },
  ];
}

/** 详情页字段 */
export function useDetailSchema(): DescriptionItemSchema[] {
  return [
    {
      label: '内容SHA256哈希',
      field: 'contentHash',
    },
    {
      label: '案号',
      field: 'caseNo',
    },
    {
      label: '案由',
      field: 'caseCause',
    },
    {
      label: '审理程序（一审/二审/再审等）',
      field: 'trialProcedure',
    },
    {
      label: '审理法院',
      field: 'courtName',
    },
    {
      label: '裁判时间',
      field: 'judgmentDate',
      render: (val) => formatDate(val, 'YYYY-MM-DD') as string,
    },
    {
      label: '当事人信息结构化数据(zlib压缩)',
      field: 'partyInfo',
      render: (val) =>
        h('div', {
          innerHTML: val,
          class: 'whitespace-pre-wrap text-sm leading-relaxed',
        }),
    },
    {
      label: '裁判结果',
      field: 'judgmentResult',
      render: (val) =>
        h('div', {
          innerHTML: val,
          class: 'whitespace-pre-wrap text-sm leading-relaxed',
        }),
    },
    {
      label: '争议焦点(zlib压缩)',
      field: 'disputeFocus',
      render: (val) =>
        h('div', {
          innerHTML: val,
          class: 'whitespace-pre-wrap text-sm leading-relaxed',
        }),
    },
    {
      label: '案件概述(zlib压缩)',
      field: 'caseSummary',
      render: (val) =>
        h('div', {
          innerHTML: val,
          class: 'whitespace-pre-wrap text-sm leading-relaxed',
        }),
    },
    {
      label: '法院查明(zlib压缩)',
      field: 'courtFindings',
      render: (val) =>
        h('div', {
          innerHTML: val,
          class: 'whitespace-pre-wrap text-sm leading-relaxed',
        }),
    },
    {
      label: '法院认为(zlib压缩)',
      field: 'courtOpinion',
      render: (val) =>
        h('div', {
          innerHTML: val,
          class: 'whitespace-pre-wrap text-sm leading-relaxed',
        }),
    },
    {
      label: '全文压缩',
      field: 'fullText',
      render: (val) =>
        h('div', {
          innerHTML: val,
          class: 'whitespace-pre-wrap text-sm leading-relaxed',
        }),
    },
    {
      label: '原文长度',
      field: 'textLength',
    },
    {
      label: '适用法条',
      field: 'judicialRules',
      render: (val) =>
        h('div', {
          innerHTML: val,
          class: 'whitespace-pre-wrap text-sm leading-relaxed',
        }),
    },
  ];
}

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'contentHash',
      label: '内容SHA256哈希',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入内容SHA256哈希',
      },
    },
    {
      fieldName: 'caseNo',
      label: '案号',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入案号',
      },
    },
    {
      fieldName: 'caseCause',
      label: '案由',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入案由',
      },
    },
    {
      fieldName: 'trialProcedure',
      label: '审理程序（一审/二审/再审等）',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入审理程序（一审/二审/再审等）',
      },
    },
    {
      fieldName: 'courtName',
      label: '审理法院',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入审理法院',
      },
    },
    {
      fieldName: 'judgmentDate',
      label: '裁判时间',
      component: 'DatePicker',
      componentProps: {
        showTime: false,
        format: 'YYYY-MM-DD',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'createTime',
      label: '创建时间',
      component: 'DatePicker',
      componentProps: {
        showTime: false,
        format: 'YYYY-MM-DD',
        valueFormat: 'x',
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions<LawCaseContentApi.CaseContent>['columns'] {
  return [
    { type: 'checkbox', width: 40 },
    {
      field: 'id',
      title: '案件id',
      minWidth: 120,
      visible: false,
    },
    {
      field: 'contentHash',
      title: '内容SHA256哈希',
      minWidth: 120,
    },
    {
      field: 'caseNo',
      title: '案号',
      minWidth: 120,
    },
    {
      field: 'caseCause',
      title: '案由',
      minWidth: 120,
    },
    {
      field: 'trialProcedure',
      title: '审理程序（一审/二审/再审等）',
      minWidth: 120,
    },
    {
      field: 'courtName',
      title: '审理法院',
      minWidth: 120,
    },
    {
      field: 'judgmentDate',
      title: '裁判时间',
      minWidth: 120,
    },
    {
      field: 'partyInfo',
      title: '当事人信息结构化数据(zlib压缩)',
      minWidth: 120,
    },
    {
      field: 'judgmentResult',
      title: '裁判结果',
      minWidth: 120,
    },
    {
      field: 'disputeFocus',
      title: '争议焦点(zlib压缩)',
      minWidth: 120,
    },
    {
      field: 'caseSummary',
      title: '案件概述(zlib压缩)',
      minWidth: 120,
    },
    {
      field: 'courtFindings',
      title: '法院查明(zlib压缩)',
      minWidth: 120,
    },
    {
      field: 'courtOpinion',
      title: '法院认为(zlib压缩)',
      minWidth: 120,
    },
    {
      field: 'fullText',
      title: '全文压缩',
      minWidth: 120,
    },
    {
      field: 'textLength',
      title: '原文长度',
      minWidth: 120,
    },
    {
      field: 'judicialRules',
      title: '适用法条',
      minWidth: 120,
    },
    {
      field: 'createTime',
      title: '创建时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      field: 'actions',
      title: '操作',
      width: 200,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}
